package com.yuelao.thread.demo;

import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * ConcurrentHashMap
 * 线程安全且效率较高的处理方案
 * Created by fengliye on 2017/10/6.
 */
public class ConcurrentHashMapDemo {
    public static void main(String[] args) {
     /*   try {
            dead();
        } catch (Exception e) {
            e.printStackTrace();
        }*/
     testConcurHashMap();
    }
    public static void dead() throws Exception {
        final HashMap<String, String> map = new HashMap<>(2);
        Thread t = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                new Thread(() -> {
                    System.out.println(System.currentTimeMillis());
                    map.put(UUID.randomUUID().toString(), "");
                }).start();
            }
        });
        t.start();
        t.join();
    }

    public static void testConcurHashMap() {
        ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap();
        concurrentHashMap.put("name", "feng");
        System.out.println(concurrentHashMap.get("name"));
    }
}
